package com.fr.cell;

import com.fr.base.BaseUtils;
import com.fr.base.FRContext;
import com.fr.base.Inter;
import com.fr.base.core.GraphHelper;
import com.fr.cell.core.GUICoreUtils;
import com.fr.cell.core.ReportPaneEditState;
import com.fr.cell.core.layout.LayoutFactory;
import com.fr.cell.undo.UndoState;
import com.fr.report.TemplateReport;
import com.fr.report.TemplateWorkBook;
import com.fr.report.WorkBook;
import com.fr.report.WorkSheet;
import com.fr.report.core.SheetUtils;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.geom.GeneralPath;
import java.awt.geom.Line2D.Double;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JSplitPane;
import javax.swing.JToolBar;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

public class JWorkBook extends ReportPane
{
  private WorkBook book;
  private int selectedIndex;
  private List reportPaneEditStateList;
  private int scrollIndex;
  private JSplitPane splitpane;
  private TabPane tabPane;
  private JButton firstButton;
  private JButton leftButton;
  private JButton rightButton;
  private JButton lastButton;
  private ActionListener reportListItemListener;

  public JWorkBook()
  {
    this(new WorkBook(new WorkSheet()));
  }

  public JWorkBook(WorkBook paramWorkBook)
  {
    this.reportPaneEditStateList = new ArrayList();
    this.scrollIndex = -1;
    this.reportListItemListener = new ActionListener(this)
    {
      private final JWorkBook this$0;

      public void actionPerformed()
      {
        String str = paramActionEvent.getActionCommand();
        int i = Integer.parseInt(str);
        this.this$0.getGrid().stopEditing();
        this.this$0.setSelectedIndex(i);
        JWorkBook.access$600(this.this$0).repaint();
      }
    };
    setWorkBook(paramWorkBook, 0);
    undoRecord();
  }

  public TemplateWorkBook getTemplate()
  {
    return getWorkBook();
  }

  public WorkBook getWorkBook()
  {
    return this.book;
  }

  public void setWorkBook(WorkBook paramWorkBook)
  {
    setWorkBook(paramWorkBook, getSelectedIndex());
  }

  public void setWorkBook(WorkBook paramWorkBook, int paramInt)
  {
    if (paramWorkBook == null)
      return;
    if (paramWorkBook.getReportCount() == 0)
      paramWorkBook.addReport(new WorkSheet());
    this.book = paramWorkBook;
    setSelectedIndex(paramInt);
  }

  public int getSelectedIndex()
  {
    return this.selectedIndex;
  }

  public void setSelectedIndex(int paramInt)
  {
    if (paramInt < 0)
      paramInt = 0;
    else if (paramInt >= getWorkBook().getReportCount())
      paramInt = getWorkBook().getReportCount() - 1;
    this.selectedIndex = paramInt;
    setEditingReport(getWorkBook().getTemplateReport(paramInt));
  }

  public void setEditingReport(TemplateReport paramTemplateReport)
  {
    if (paramTemplateReport == null)
      return;
    this.scrollIndex = 0;
    super.setEditingReport(paramTemplateReport);
  }

  protected JComponent horizontalBar()
  {
    JPanel localJPanel = new JPanel();
    localJPanel.setLayout(LayoutFactory.createBorderLayout());
    JToolBar localJToolBar = new JToolBar();
    localJToolBar.setFloatable(false);
    localJToolBar.setRollover(true);
    localJPanel.add(localJToolBar, "West");
    localJToolBar.setLayout(new GridLayout(1, 4, 0, 0));
    this.firstButton = new JButton(BaseUtils.readIcon("/com/fr/cell/images/tabscroll/first.png"));
    this.leftButton = new JButton(BaseUtils.readIcon("/com/fr/cell/images/tabscroll/left.png"));
    this.rightButton = new JButton(BaseUtils.readIcon("/com/fr/cell/images/tabscroll/right.png"));
    this.lastButton = new JButton(BaseUtils.readIcon("/com/fr/cell/images/tabscroll/last.png"));
    localJToolBar.add(this.firstButton);
    localJToolBar.add(this.leftButton);
    localJToolBar.add(this.rightButton);
    localJToolBar.add(this.lastButton);
    this.firstButton.addMouseListener(createMouseListener());
    this.leftButton.addMouseListener(createMouseListener());
    this.rightButton.addMouseListener(createMouseListener());
    this.lastButton.addMouseListener(createMouseListener());
    Dimension localDimension = new Dimension(18, 18);
    this.firstButton.setPreferredSize(localDimension);
    this.leftButton.setPreferredSize(localDimension);
    this.rightButton.setPreferredSize(localDimension);
    this.lastButton.setPreferredSize(localDimension);
    this.tabPane = new TabPane(this);
    localJPanel.add(this.tabPane, "Center");
    localJPanel.setPreferredSize(new Dimension(480, 18));
    this.splitpane = new JSplitPane(1, localJPanel, this.horScrollBar);
    this.splitpane.setBorder(null);
    this.splitpane.setDividerSize(6);
    this.splitpane.setDividerLocation(this.splitpane.getPreferredSize().width * 3 / 4);
    return this.splitpane;
  }

  public void fireReportDataChanged()
  {
    if (isSupportDefaultParentCalculate())
      SheetUtils.calculateDefaultParent(getEditingReport());
    fireReportDataChangeListener();
    repaint();
  }

  protected UndoState createUndoState()
  {
    if (getWorkBook() == null)
      return null;
    GridSelection localGridSelection = null;
    try
    {
      localGridSelection = (GridSelection)getGridSelection().clone();
    }
    catch (CloneNotSupportedException localCloneNotSupportedException)
    {
      FRContext.getLogger().log(Level.WARNING, localCloneNotSupportedException.getMessage(), localCloneNotSupportedException);
    }
    int i = getGrid().getVerticalValue();
    int j = getGrid().getHorizontalValue();
    return new WorkBookState(this, this, localGridSelection, i, j, isUndoCacheable());
  }

  private MouseListener createMouseListener()
  {
    1 local1 = new MouseAdapter(this)
    {
      private final JWorkBook this$0;

      public void mousePressed()
      {
        Object localObject1;
        if (SwingUtilities.isLeftMouseButton(paramMouseEvent))
        {
          this.this$0.getGrid().stopEditing();
          localObject1 = this.this$0.getWorkBook();
          int i = ((WorkBook)localObject1).getReportCount();
          if (i < 2)
            return;
          Object localObject2 = paramMouseEvent.getSource();
          if (localObject2.equals(JWorkBook.access$000(this.this$0)))
            JWorkBook.access$102(this.this$0, 0);
          else if (localObject2.equals(JWorkBook.access$200(this.this$0)))
            if (JWorkBook.access$300(this.this$0) > 0)
              JWorkBook.access$102(this.this$0, JWorkBook.access$306(this.this$0));
          else if (localObject2.equals(JWorkBook.access$400(this.this$0)))
            if (JWorkBook.access$300(this.this$0) < i - 1)
              JWorkBook.access$102(this.this$0, JWorkBook.access$304(this.this$0));
          else if (localObject2.equals(JWorkBook.access$500(this.this$0)))
            JWorkBook.access$102(this.this$0, i - 1);
          this.this$0.setSelectedIndex(JWorkBook.access$100(this.this$0));
          JWorkBook.access$600(this.this$0).repaint();
        }
        if (SwingUtilities.isRightMouseButton(paramMouseEvent))
        {
          localObject1 = new JPopupMenu();
          WorkBook localWorkBook = this.this$0.getWorkBook();
          int j = localWorkBook.getReportCount();
          for (int k = 0; k < j; ++k)
          {
            String str = localWorkBook.getReportName(k);
            JMenuItem localJMenuItem = new JMenuItem(str);
            ((JPopupMenu)localObject1).add(localJMenuItem);
            localJMenuItem.addActionListener(JWorkBook.access$700(this.this$0));
            localJMenuItem.setActionCommand("" + k);
          }
          Dimension localDimension = ((JPopupMenu)localObject1).getPreferredSize();
          ((JPopupMenu)localObject1).show((Component)paramMouseEvent.getSource(), paramMouseEvent.getX() + 1, paramMouseEvent.getY() - 1 - localDimension.height);
        }
      }
    };
    return local1;
  }

  protected void changeBackUpTempalte(TemplateWorkBook paramTemplateWorkBook)
  {
  }

  public TemplateWorkBook getBackUpTempalte()
  {
    return null;
  }

  public void setBackUpTemplate(TemplateWorkBook paramTemplateWorkBook)
  {
  }

  static JButton access$000(JWorkBook paramJWorkBook)
  {
    return paramJWorkBook.firstButton;
  }

  static int access$102(JWorkBook paramJWorkBook, int paramInt)
  {
    return (paramJWorkBook.scrollIndex = paramInt);
  }

  static JButton access$200(JWorkBook paramJWorkBook)
  {
    return paramJWorkBook.leftButton;
  }

  static int access$300(JWorkBook paramJWorkBook)
  {
    return paramJWorkBook.selectedIndex;
  }

  static int access$306(JWorkBook paramJWorkBook)
  {
    return (--paramJWorkBook.selectedIndex);
  }

  static JButton access$400(JWorkBook paramJWorkBook)
  {
    return paramJWorkBook.rightButton;
  }

  static int access$304(JWorkBook paramJWorkBook)
  {
    return (++paramJWorkBook.selectedIndex);
  }

  static JButton access$500(JWorkBook paramJWorkBook)
  {
    return paramJWorkBook.lastButton;
  }

  static int access$100(JWorkBook paramJWorkBook)
  {
    return paramJWorkBook.scrollIndex;
  }

  static TabPane access$600(JWorkBook paramJWorkBook)
  {
    return paramJWorkBook.tabPane;
  }

  static ActionListener access$700(JWorkBook paramJWorkBook)
  {
    return paramJWorkBook.reportListItemListener;
  }

  static List access$800(JWorkBook paramJWorkBook)
  {
    return paramJWorkBook.reportPaneEditStateList;
  }

  private class TabPane extends JComponent
    implements MouseListener, MouseMotionListener
  {
    boolean isBlank;
    private int[] xyPressedCoordinate;
    private int[] xyReleasedCoordinate;
    private int[] widthArray;
    private List linearray;
    private boolean isReleased;
    private final JWorkBook this$0;

    public TabPane()
    {
      this.this$0 = paramJWorkBook;
      this.xyPressedCoordinate = new int[] { 0, 0 };
      this.xyReleasedCoordinate = new int[] { 0, 0 };
      this.linearray = new ArrayList();
      this.isReleased = false;
      addMouseListener(this);
      addMouseMotionListener(this);
    }

    public void mouseDragged()
    {
      this.linearray.add(paramMouseEvent.getPoint());
      repaint();
    }

    public void mouseMoved()
    {
    }

    public void paintComponent()
    {
      int i1;
      int i4;
      Object localObject;
      super.paintComponent(paramGraphics);
      Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
      FontMetrics localFontMetrics = GraphHelper.getFontMetrics(getFont());
      double d1 = 0.0D;
      int i = localFontMetrics.charWidth('M');
      int j = localFontMetrics.getAscent();
      double d2 = getSize().getHeight() - 1.0D;
      WorkBook localWorkBook = this.this$0.getWorkBook();
      this.widthArray = new int[localWorkBook.getReportCount()];
      for (int k = 0; k < localWorkBook.getReportCount(); ++k)
      {
        String str1 = localWorkBook.getReportName(k);
        this.widthArray[k] = (localFontMetrics.stringWidth(str1) + i * 2 - 1);
      }
      k = this.this$0.getSelectedIndex();
      if ((JWorkBook.access$100(this.this$0) >= 0) && (JWorkBook.access$100(this.this$0) < localWorkBook.getReportCount()))
      {
        int l = localWorkBook.getReportCount();
        for (i1 = JWorkBook.access$100(this.this$0); i1 < l; ++i1)
        {
          Color localColor;
          String str2 = localWorkBook.getReportName(i1);
          if (i1 == k)
            localColor = UIManager.getColor("TabbedPane.highlight");
          else
            localColor = UIManager.getColor("TabbedPane.background");
          i4 = localFontMetrics.stringWidth(str2) + i * 2 - 1;
          int i5 = 6;
          localObject = new double[] { d1, d1, d1 + i5, d1 + i4, d1 + i4 };
          double[] arrayOfDouble1 = { 0.0D, d2 - i5, d2, d2, 0.0D };
          localGraphics2D.setPaint(localColor);
          GeneralPath localGeneralPath = new GeneralPath(0, localObject.length);
          localGeneralPath.moveTo((float)localObject[0], (float)arrayOfDouble1[0]);
          for (int i6 = 1; i6 < localObject.length; ++i6)
            localGeneralPath.lineTo((float)localObject[i6], (float)arrayOfDouble1[i6]);
          localGeneralPath.closePath();
          localGraphics2D.fill(localGeneralPath);
          localGraphics2D.setPaint(UIManager.getColor("TabbedPane.darkShadow"));
          if (i1 == JWorkBook.access$100(this.this$0))
            localGraphics2D.draw(new Line2D.Double(localObject[0], arrayOfDouble1[0], localObject[1], arrayOfDouble1[1]));
          localGraphics2D.draw(new Line2D.Double(localObject[1], arrayOfDouble1[1], localObject[2], arrayOfDouble1[2]));
          localGraphics2D.draw(new Line2D.Double(localObject[2], arrayOfDouble1[2], localObject[3], arrayOfDouble1[3]));
          localGraphics2D.draw(new Line2D.Double(localObject[3], arrayOfDouble1[3], localObject[4], arrayOfDouble1[4]));
          if (i1 != k)
            localGraphics2D.draw(new Line2D.Double(localObject[4], arrayOfDouble1[4], localObject[0], arrayOfDouble1[0]));
          if (i1 != k)
          {
            localGraphics2D.setPaint(UIManager.getColor("TabbedPane.selected"));
            double[] arrayOfDouble2 = { d1, d1, d1 + i5 };
            double[] arrayOfDouble3 = { 1.0D, d2 - i5 - 1.0D, d2 - 1.0D };
            if (i1 == JWorkBook.access$100(this.this$0))
            {
              arrayOfDouble2[0] += 1.0D;
              arrayOfDouble2[1] += 1.0D;
            }
            localGraphics2D.draw(new Line2D.Double(arrayOfDouble2[0], arrayOfDouble3[0], arrayOfDouble2[1], arrayOfDouble3[1]));
            localGraphics2D.draw(new Line2D.Double(arrayOfDouble2[1], arrayOfDouble3[1], arrayOfDouble2[2], arrayOfDouble3[2]));
          }
          localGraphics2D.setPaint(getForeground());
          localGraphics2D.drawString(str2, (int)d1 + i, j);
          d1 += i4 + 1;
        }
      }
      localGraphics2D.setPaint(UIManager.getColor("TabbedPane.darkShadow"));
      localGraphics2D.draw(new Line2D.Double(d1, 0.0D, getSize().getWidth(), 0.0D));
      if (!(this.linearray.isEmpty()))
      {
        localGraphics2D.setPaint(UIManager.getColor("TabbedPane.darkShadow"));
        Point localPoint = (Point)this.linearray.get(this.linearray.size() - 1);
        i1 = getPressedXY()[0];
        int i2 = this.widthArray[k];
        int i3 = 0;
        for (i4 = 0; i4 < k; ++i4)
          i3 += this.widthArray[i4];
        i4 = i1 - i3;
        int[] arrayOfInt = { (int)localPoint.getX() - i4, (int)localPoint.getX() - i4, (int)localPoint.getX() + 5 - i4, (int)localPoint.getX() - i4 + i2, (int)localPoint.getX() + i2 - i4 };
        localObject = new int[] { 0, (int)d2 * 2 / 3, (int)d2, (int)d2, 0 };
        localGraphics2D.drawPolygon(arrayOfInt, localObject, 5);
        localGraphics2D.setPaint(getForeground());
        localGraphics2D.drawString(localWorkBook.getReportName(k), (int)localPoint.getX() - i4 + i, j);
      }
      if (this.isReleased)
        this.linearray.clear();
    }

    public int[] getPressedXY()
    {
      return this.xyPressedCoordinate;
    }

    public void setPressedXY(, int paramInt2)
    {
      this.xyPressedCoordinate[0] = paramInt1;
      this.xyPressedCoordinate[1] = paramInt2;
    }

    public int[] getReleasedXY()
    {
      return this.xyReleasedCoordinate;
    }

    public void setReleasedXY(, int paramInt2)
    {
      this.xyReleasedCoordinate[0] = paramInt1;
      this.xyReleasedCoordinate[1] = paramInt2;
    }

    public void mouseClicked()
    {
    }

    public void mousePressed()
    {
      int i2;
      Object localObject;
      WorkBook localWorkBook = this.this$0.getWorkBook();
      if ((JWorkBook.access$100(this.this$0) < 0) || (JWorkBook.access$100(this.this$0) >= localWorkBook.getReportCount()))
        return;
      int i = paramMouseEvent.getX();
      int j = paramMouseEvent.getY();
      setPressedXY(i, j);
      this.isBlank = true;
      FontMetrics localFontMetrics = GraphHelper.getFontMetrics(getFont());
      int k = 0;
      int l = localFontMetrics.charWidth('M');
      int i1 = localWorkBook.getReportCount();
      if (JWorkBook.access$800(this.this$0).size() < i1)
        for (i2 = i1 - JWorkBook.access$800(this.this$0).size(); i2 >= 0; --i2)
          JWorkBook.access$800(this.this$0).add(new ReportPaneEditState());
      ReportPaneEditState localReportPaneEditState = (ReportPaneEditState)JWorkBook.access$800(this.this$0).get(JWorkBook.access$300(this.this$0));
      localReportPaneEditState.backupJWorkBook(this.this$0);
      for (int i3 = JWorkBook.access$100(this.this$0); i3 < i1; ++i3)
      {
        localObject = localWorkBook.getReportName(i3);
        int i4 = localFontMetrics.stringWidth((String)localObject) + l * 2;
        if ((i >= k) && (i < k + i4))
        {
          this.this$0.getGrid().stopEditing();
          this.this$0.setSelectedIndex(i3);
          localReportPaneEditState = (ReportPaneEditState)JWorkBook.access$800(this.this$0).get(i3);
          localReportPaneEditState.popupJWorkBook(this.this$0);
          localReportPaneEditState.backupJWorkBook(this.this$0);
          this.isBlank = false;
          this.this$0.repaint(40L);
          break;
        }
        k += i4;
      }
      if (SwingUtilities.isRightMouseButton(paramMouseEvent))
      {
        JPopupMenu localJPopupMenu = new JPopupMenu();
        localObject = new JMenuItem(Inter.getLocText("Insert"));
        ((JMenuItem)localObject).setIcon(BaseUtils.readIcon("/com/fr/cell/images/control/add.png"));
        localJPopupMenu.add((JMenuItem)localObject);
        ((JMenuItem)localObject).addActionListener(new JWorkBook.3(this));
        JMenuItem localJMenuItem1 = new JMenuItem(Inter.getLocText("Remove"));
        localJMenuItem1.setIcon(BaseUtils.readIcon("/com/fr/cell/images/control/remove.png"));
        localJPopupMenu.add(localJMenuItem1);
        if ((this.isBlank) || (localWorkBook.getReportCount() <= 1))
          localJMenuItem1.setEnabled(false);
        localJMenuItem1.addActionListener(new JWorkBook.4(this));
        JMenuItem localJMenuItem2 = new JMenuItem(Inter.getLocText("Rename"));
        localJMenuItem2.setIcon(BaseUtils.readIcon("/com/fr/cell/images/control/rename.png"));
        localJPopupMenu.add(localJMenuItem2);
        if (this.isBlank)
          localJMenuItem2.setEnabled(false);
        localJMenuItem2.addActionListener(new JWorkBook.5(this));
        GUICoreUtils.showPopupMenu(localJPopupMenu, this, i - 1, j - 1);
      }
    }

    public void mouseReleased()
    {
      this.isReleased = true;
      setReleasedXY(paramMouseEvent.getX(), paramMouseEvent.getY());
      if ((getPressedXY()[0] != getReleasedXY()[0]) || (getPressedXY()[1] != getReleasedXY()[1]))
      {
        int l;
        WorkBook localWorkBook = this.this$0.getWorkBook();
        ReportPaneEditState localReportPaneEditState = (ReportPaneEditState)JWorkBook.access$800(this.this$0).get(this.this$0.getSelectedIndex());
        localReportPaneEditState.backupJWorkBook(this.this$0);
        int i = this.this$0.getSelectedIndex();
        int j = getReleasedXY()[0] - getPressedXY()[0];
        int k = getPressedXY()[0] - getReleasedXY()[0];
        if (j > this.widthArray[i] / 2)
        {
          if (this.this$0.getSelectedIndex() < localWorkBook.getReportCount() - 1)
            while (j > this.widthArray[i] / 2)
            {
              l = this.this$0.getSelectedIndex();
              localWorkBook = exchangeWorkSheet(localWorkBook, this.this$0.getSelectedIndex(), this.this$0.getSelectedIndex() + 1);
              this.this$0.setSelectedIndex(this.this$0.getSelectedIndex() + 1);
              if (l > localWorkBook.getReportCount() - 3)
              {
                this.this$0.setSelectedIndex(localWorkBook.getReportCount() - 1);
                return;
              }
              j -= this.widthArray[(l + 1)];
            }
          return;
        }
        if (k > this.widthArray[i] / 2)
        {
          if (this.this$0.getSelectedIndex() > 0)
            while (k > this.widthArray[i] / 2)
            {
              l = this.this$0.getSelectedIndex();
              localWorkBook = exchangeWorkSheet(localWorkBook, this.this$0.getSelectedIndex(), this.this$0.getSelectedIndex() - 1);
              this.this$0.setSelectedIndex(this.this$0.getSelectedIndex() - 1);
              if (l < 2)
              {
                this.this$0.setSelectedIndex(0);
                return;
              }
              k -= this.widthArray[(l - 1)];
            }
          return;
        }
        this.this$0.setSelectedIndex(i);
      }
    }

    public void mouseEntered()
    {
    }

    public void mouseExited()
    {
    }

    private WorkBook exchangeWorkSheet(, int paramInt1, int paramInt2)
    {
      WorkSheet localWorkSheet1 = new WorkSheet();
      localWorkSheet1 = (WorkSheet)paramWorkBook.getReport(paramInt1);
      String str1 = paramWorkBook.getReportName(paramInt1);
      WorkSheet localWorkSheet2 = new WorkSheet();
      localWorkSheet2 = (WorkSheet)paramWorkBook.getReport(paramInt2);
      String str2 = paramWorkBook.getReportName(paramInt2);
      paramWorkBook.addReport(paramInt1, str2, localWorkSheet2);
      paramWorkBook.removeReport(paramInt1 + 1);
      paramWorkBook.addReport(paramInt2, str1, localWorkSheet1);
      paramWorkBook.removeReport(paramInt2 + 1);
      return paramWorkBook;
    }

    static JWorkBook access$900(TabPane paramTabPane)
    {
      return paramTabPane.this$0;
    }
  }

  private class WorkBookState extends UndoState
    implements Serializable, Cloneable
  {
    private WorkBook book;
    private int selectedIndex;
    private final JWorkBook this$0;

    public WorkBookState(, JWorkBook paramJWorkBook2, GridSelection paramGridSelection, int paramInt1, int paramInt2, boolean paramBoolean)
    {
      super(paramJWorkBook2, paramGridSelection, paramInt1, paramInt2, paramBoolean);
      this.this$0 = paramJWorkBook1;
    }

    protected void evaluateReportTemplate()
    {
      try
      {
        this.book = ((WorkBook)((JWorkBook)this.reportPane).getWorkBook().clone());
      }
      catch (CloneNotSupportedException localCloneNotSupportedException)
      {
        FRContext.getLogger().log(Level.WARNING, localCloneNotSupportedException.getMessage(), localCloneNotSupportedException);
        return;
      }
      this.selectedIndex = ((JWorkBook)this.reportPane).getSelectedIndex();
      if (this.isCacheable)
        try
        {
          this.cacheFile = new File(getCacheDirectory(), "Undo" + System.currentTimeMillis() + "_" + (int)(Math.random() * 1000.0D));
          for (int i = 0; this.cacheFile.exists(); ++i)
            this.cacheFile = new File(getCacheDirectory(), "Undo" + System.currentTimeMillis() + "_" + (int)(Math.random() * 1000.0D) + i);
          FileOutputStream localFileOutputStream = new FileOutputStream(this.cacheFile);
          ObjectOutputStream localObjectOutputStream = new ObjectOutputStream(localFileOutputStream);
          localObjectOutputStream.writeObject(this.book);
          localObjectOutputStream.flush();
          localObjectOutputStream.close();
          this.cacheFile.deleteOnExit();
          this.book = null;
        }
        catch (Throwable localThrowable)
        {
        }
    }

    public void applyState()
    {
      WorkBook localWorkBook = getWorkBook();
      if (localWorkBook == null)
        return;
      try
      {
        ((JWorkBook)this.reportPane).setWorkBook((WorkBook)localWorkBook.clone(), this.selectedIndex);
      }
      catch (CloneNotSupportedException localCloneNotSupportedException)
      {
        FRContext.getLogger().log(Level.WARNING, localCloneNotSupportedException.getMessage(), localCloneNotSupportedException);
      }
      super.applyState();
    }

    public WorkBook getWorkBook()
    {
      if ((this.isCacheable) && (this.book == null))
      {
        if ((this.cacheFile == null) || (!(this.cacheFile.exists())))
          return null;
        try
        {
          ObjectInputStream localObjectInputStream = new ObjectInputStream(new FileInputStream(this.cacheFile));
          WorkBook localWorkBook = (WorkBook)localObjectInputStream.readObject();
          localObjectInputStream.close();
          return localWorkBook;
        }
        catch (Throwable localThrowable)
        {
          FRContext.getLogger().log(Level.WARNING, localThrowable.getMessage(), localThrowable);
        }
      }
      return this.book;
    }
  }
}